<#macro tagsRow typeId='' typeName=''>
<dl class="nowrap tags">
	<dt>${typeName?has_content?then(typeName,'标签')}:</dt>
	<dd>
		<div id="tags${typeId!}" class="tagsBox"></div>
		<input name="tag[${typeId!}].id" type="hidden"/>
		<input name="tag[${typeId!}].name" type="text" size="30" postField="name" suggestfields="id,name" lookupgroup="tag[${typeId!}]" suggestUrl="common/tagSuggest.html?typeId=${typeId!}"/>
		<a class="button" href="javascript:;" onclick="addTag('${typeId}',$('input[name=\'tag[${typeId!}].id\']',navTab.getCurrentPanel()).val(),$('input[name=\'tag[${typeId!}].name\']',navTab.getCurrentPanel()).val());return false;"><span>增加</span></a>
		<span class="info">点击某个标签可以将其删除</span>
	</dd>
</dl>
</#macro>
<#macro tags typeIds='' tagIds=''>
<style>
.tagsBox{line-height:25px;}
.tagsBox span{margin-right:8px;padding:3px;border:1px solid #aaa;}
</style>
	<#if typeIds?has_content>
		<@_tagType ids=typeIds>
			<#list map?keys as k>
<@tagsRow k map[k].name/>
			</#list>
		</@_tagType>
	<#else>
<@tagsRow/>
	</#if>
<script>
function addTag(typeId,$id,$name){
	if($name){
		$name=$name.trim();
	}
	if($('#tags'+typeId+' span',navTab.getCurrentPanel()).size()>20){
		alertMsg.error('标签不能超过20个');
	}else{
		if($id&&$name){
			$('#tags'+typeId,navTab.getCurrentPanel()).append("<span><a href=\"javascript:;\" onclick=\"$(this).parent().remove();reIndex();return false;\">"+$name+"</a><input type=\"hidden\" name=\"tags[].id\" value=\""+$id+"\"/></span>");
		}else if($name){
			$('#tags'+typeId,navTab.getCurrentPanel()).append("<span><a href=\"javascript:;\" onclick=\"$(this).parent().remove();reIndex();return false;\">"+$name+"</a><input type=\"hidden\" name=\"tags[].name\" value=\""+$name+"\"/><input type=\"hidden\" name=\"tags[].typeId\" value=\""+typeId+"\"/></span>");
		}
		reIndex();
	}
	$('input[name=\'tag['+typeId+'].id\']',navTab.getCurrentPanel()).val('');
	$('input[name=\'tag['+typeId+'].typeId\']',navTab.getCurrentPanel()).val('');
	$('input[name=\'tag['+typeId+'].name\']',navTab.getCurrentPanel()).val('');
}
function reIndex(){
	var tagIndex=0;
	$('.tagsBox span',navTab.getCurrentPanel()).each(function(){
		$('input[name$=\\.id]',this).attr('name','tags['+tagIndex+'].id');
		$('input[name$=\\.name]',this).attr('name','tags['+tagIndex+'].name');
		$('input[name$=\\.typeId]',this).attr('name','tags['+tagIndex+'].typeId');
		tagIndex++;
	});
}
	<@_tag ids=tagIds>
		<#list map?keys as k>
			<#if typeIds?has_content>
addTag('${map[k].typeId!}','${k}','${map[k].name?js_string}','${map[k].typeId!}');
			<#else>
addTag('','${k}','${map[k].name?js_string}','${map[k].typeId!}');
			</#if>
		</#list>
	</@_tag>
</script>
</#macro>